package cn.amarone.scaffold.config.business.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;

/**
 * @author Amarone
 * @version 1.0
 * @description: 统一的响应字段封装
 * @date 2023/8/1 16:16
 */
@Data
@Schema(title = "公共响应实体")
public class BaseRsp<T> {

    @Builder.Default
    @Schema(description = "业务响应状态码")
    private int code = 200;
    @Builder.Default
    @Schema(description = "业务响应信息")
    private String msg = "SUCCESS";
    @Builder.Default
    @Schema(description = "业务响应时间")
    private Long rspTime = System.currentTimeMillis();
    @Schema(description = "业务响应数据")
    private T data;

    public BaseRsp() {
    }

    public BaseRsp(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseRsp(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseRsp success(T data) {
        return new BaseRsp(200, "SUCCESS", data);
    }

    public static BaseRsp error(String msg) {
        return new BaseRsp(500, msg);
    }

    public static BaseRsp success() {
        return new BaseRsp(200, "SUCCESS");
    }
}
